package com.core.ui.controller.base;

import java.util.ArrayList;
import java.util.Iterator;

import com.core.managers.SessionManager;
import com.model.KeyValue;

public class ServletDependenceController
        extends CustomController {

	private ArrayList <String> servletParamNamesAsId = null;



	// public String getServletParamNameAsId() {
	// return servletParamNameAsId;
	// }

	protected void addServletParamNameAsId ( String servletParamNameAsId ) {

		// TODO: obsolette
		if ( this.servletParamNamesAsId == null ) {
			this.servletParamNamesAsId = new ArrayList <String>();
		}
		this.servletParamNamesAsId.add(servletParamNameAsId);
	}



	protected ArrayList <KeyValue> servletParamValueAsId ( String servletName ) {

		ArrayList <KeyValue> result = new ArrayList <KeyValue>();
		if ( this.servletParamNamesAsId != null ) {

			SessionManager sessionManager = SessionManager.sharedInstance();

			Iterator <String> iterator = this.servletParamNamesAsId.iterator();
			while ( iterator.hasNext() ) {
				String param = iterator.next();
				KeyValue value = sessionManager.servletParamValue(servletName, param, null);
				if ( value != null ) {
					result.add(value);
				}
			}

		}

		return result;

	}



	public ArrayList <KeyValue> currentServletParamValueAsId () {

		SessionManager sessionManager = SessionManager.sharedInstance();

		String servletName = sessionManager.servletName();
		return this.servletParamValueAsId(servletName);
	}

}
